export const schema = {
    type: "page",
    title: "Banner 管理",
    toolbar: {
        type: "button",
        icon: "fa fa-plus pull-left",
        level: "success",
        label: "新建",
        actionType: "dialog",
        dialog: {
            title: "新建 Banner",
            body: {
                type: "form",
                api: "post:/api/banner",
                mode: "default",
                controls: [
                    {
                        type: "image",
                        label: "图片",
                        name: "photo",
                        placeholder: "请选择尺寸为 750x528 的图片，或将满足尺寸的图片拖入框内",
                        maxSize: 10 * 1024 * 1024,
                        limit: {
                            width: 750,
                            height: 528
                        }
                    },

                    /*{
                        type: "text",
                        name: "title",
                        label: "标题",
                        labelClassName: "text-muted",
                        disabled: true
                    },*/

                    {
                        type: "radios",
                        name: "jump_mode",
                        label: "跳转方式",
                        value: 0,
                        columnsCount: 4,
                        options: [
                            {
                                label: "不跳转",
                                value: 0
                            },

                            {
                                label: '地址跳转',
                                value: 1
                            },

                            // {
                            //     label: "机构页面",
                            //     value: 2,
                            //     disabled: true
                            // },

                            // {
                            //     label: "团队页面",
                            //     value: 3,
                            //     disabled: true
                            // }
                        ]
                    },

                    {
                        type: 'url',
                        name: 'href',
                        label: '跳转地址',
                        visibleOn: 'data.jump_mode == 1'
                    }
                ]
            }
        }
    },
    body: {
        type: "crud",
        api: "get:/api/banner",
        columnsTogglable: false,
        showHeader: false,
        columns: [
            {
                name: "id",
                label: "ID"
            },

            {
                name: "photo",
                label: "图片",
                type: "image",
                popOver: {
                    title: "",
                    body: '<div class="w w-xxl"><img class="w-full" src=${photo} /></div>'
                }
            },

            /*{
                name: "title",
                label: "标题"
            },*/

            {
                name: 'jump_mode',
                label: '跳转方式',
                type: 'map',
                map: {
                    '*': '<span class="label label-default">不跳转</span>',
                    '1': '<span class="label label-info">跳转到</span>：<a target="_blank" href="${href}">${href}</a>'
                }
            },

            {
                name: "status",
                width: 80,
                label: "启用",
                type: "map",
                map: {
                    "*": '<span class="label label-default">不启用</span>',
                    "1": '<span class="label label-success">启用</span>'
                }
            },

            {
                label: "操作",
                type: "operation",
                width: 180,
                buttons: [
                    {
                        type: "button",
                        size: "xs",
                        level: "info",
                        label: "编辑",
                        actionType: "dialog",
                        dialog: {
                            title: "编辑 Banner",
                            body: {
                                type: "form",
                                api: "put:/api/banner/${id}",
                                controls: [
                                    {
                                        type: "image",
                                        name: "photo",
                                        label: "图片",
                                        placeholder: "请选择尺寸为 750x528 的图片，或将满足尺寸的图片拖入框内",
                                        maxSize: 10 * 1024 * 1024,
                                        limit: {
                                            width: 750,
                                            height: 528
                                        }
                                    },

                                    /*{
                                        type: "text",
                                        name: "title",
                                        label: "标题",
                                        labelClassName: "text-muted",
                                        disabled: true
                                    },*/

                                    {
                                        type: "radios",
                                        name: "jump_mode",
                                        label: "跳转方式",
                                        columnsCount: 4,
                                        options: [
                                            {
                                                label: "不跳转",
                                                value: 0
                                            },

                                            {
                                                label: '地址跳转',
                                                value: 1
                                            },

                                            // {
                                            //     label: "机构页面",
                                            //     value: 2,
                                            //     disabled: true
                                            // },

                                            // {
                                            //     label: "团队页面",
                                            //     value: 3,
                                            //     disabled: true
                                            // }
                                        ]
                                    },

                                    {
                                        type: 'url',
                                        name: 'href',
                                        label: '跳转地址',
                                        visibleOn: 'data.jump_mode == 1'
                                    }
                                ]
                            }
                        }
                    },

                    {
                        type: "button",
                        size: "xs",
                        label: "禁用",
                        level: "warning",
                        confirmText: "确定要禁用？",
                        actionType: "ajax",
                        api: "/api/banner/offline/$id",
                        visibleOn: "data.status == 1"
                    },

                    {
                        type: "button",
                        size: "xs",
                        label: "恢复",
                        level: "success",
                        confirmText: "确定要恢复？",
                        actionType: "ajax",
                        api: "/api/banner/online/$id",
                        visibleOn: "data.status == 0"
                    },
                    {
                        type: "button",
                        size: "xs",
                        label: "删除",
                        level: "danger",
                        confirmText: "确定要删除？",
                        actionType: "ajax",
                        api: "delete:/api/banner/$id"
                    }
                ]
            }
        ]
    }
};
